package zzu.patterns.structural.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy {
    private Object target;

    JdkProxy() {}
    JdkProxy(Object target) {
        this.target = target;
    }
    public Object getProxyInstance() {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println("动态代理开始");
                Object invoke = method.invoke(target, objects);
                System.out.println("动态代理结束");
                return invoke;
            }
        });
    }

}
